var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isUser: true,
    showPage: false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options)
    var that = this
    that.setData({
      isUser: options.isUser,
      cardNumber: options.card
    })
    that.getCardDetailInfo()
  },
  getCardDetailInfo() {
    var that = this
    app.executeRequest(function (header) {
      wx.request({
        url: app.BASE_URL + '/hospitalized/getCancelNeedInfo',
        header,
        data: {
          cardNumber: that.data.cardNumber
        },
        success: (res) => {

          var data = res.data.data
          console.log(res)
          that.setData({
            totalPaymentAmount: data.totalPaymentAmount,
            totalConsumeAmount: data.totalConsumeAmount,
            cardFee: data.cardFee,
            totalRefundableBalance: data.totalRefundableBalance,
            showPage: true
          })
        }
      })

    })
  },
  confirm() {
    wx.showLoading({
      title: '加载中',
    })
    console.log(this.data.cardNumber)
    var that = this
    app.executeRequest(function (header) {
      wx.request({
        url: app.BASE_URL + '/hospitalized/cancelCard',
        header,
        data: {
          cardNum: that.data.cardNumber
        },
        success: (res) => {
          getApp().hideLoading()
          console.log(res)
          if (res.data.result == 0) {
            wx.navigateTo({
              url: '../cardDetailSuccess/cardDetailSuccess?cardNumber=' + that.data.cardNumber + '&canBack=' + that.data.canBack + '&cardPrice=' + that.data.cardPrice + '&phone=' + that.data.phone + '&time=' + res.data.data.refundTime,
            })
          } else {
            wx.showToast({
              title: res.data.description,
            })
          }
        }
      })

    })
  },
  examine() {
    wx.navigateTo({
      url: '../ICusageRecord/ICusageRecord?cardNumber=' + this.data.cardNumber,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})